package Controller;

import DaoMain.UserData;
import Service.inter.ServiceInter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/Users")
public class User1 {
    @Autowired
    ServiceInter si;
    @GetMapping
    public Resultful SelectAll(){
        List<UserData> udl=si.GetUserAll();
        System.out.println(udl+"///////////////////////////");
        return new Resultful(udl!=null?Code.GET_SUCC:Code.GET_ERRO,udl);
    }
    @GetMapping("/{Id}")
    public Resultful Selectone(@PathVariable int Id){
        UserData ud=si.GetUser(Id);
        return new Resultful(ud!=null?Code.GET_SUCC:Code.GET_ERRO,ud);
    }
    @PostMapping
    public  Resultful InsertUser(@RequestBody UserData ud){
        boolean g=si.InsertUser(ud);
        return new Resultful(g?Code.INSERT_SUCC:Code.INSERT_ERRO,ud);
    }
    @DeleteMapping("/{id}")
    public Resultful DeleteUser(@PathVariable  int id){
        boolean g=si.DeleteUser(id);
        return new Resultful(g?Code.DELETE_SUCC:Code.DELETE_ERRO,g);
    }
    @PutMapping
    public Resultful UpDataUser(@RequestBody  UserData ud){
        boolean g= si.UpData(ud);
        return new Resultful(g?Code.UPDATA_SUCC:Code.UPDATA_ERRO,g);
    }
}
